<?php
namespace app\common\model;

use think\Model;

class Certification extends Model
{
    /**
     * @param $proposer
     * @param $card_no
     * @param $member_id
     * @param $source
     * @return array|bool
     */
    public function add($proposer, $card_no, $member_id, $source) {
        $data = [
            'proposer' => $proposer,
            'card_no' => $card_no,
            'member_id' => $member_id,
            'source' => $source,
            'status' => 1,
            'add_time' => time()
        ];

        /*调用验证器 验证数据*/
        $validate = validate('Certification');
        //判断是否可以申请
        if (!$validate->scene('add')->check($data)) {
            return ['code'=>$validate->getError(),'msg'=> 'FAULT'];
        }

        $certification = $this->get(['member_id' => $member_id]);
        if ($certification) {
            // 已存在
            return false;
        }

        $this->data($data);
        $this->save();

    }
}
